package com.ys.other;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * 描述: 使用IO完成文件的复制粘贴, C:\abc.txt的数据复制到D:\abc.txt
 *
 * @author CodeYang
 * @version 2021/1/14 14:36
 */
public class P2Test {

    public static void main(String[] args) {
        // 1 获得 c abc.txt 的数据


        try(
                // in
                FileInputStream fis = new FileInputStream("C:/abc.txt");
                // 缓冲流装饰
                BufferedInputStream bis = new BufferedInputStream(fis);
                // out
                FileOutputStream fos = new FileOutputStream("D:/abc.txt");
                BufferedOutputStream bos = new BufferedOutputStream(fos);
             )
         {
             // 1 ; 读
             byte[] data = new byte[1024];
             int len = 0;
             while ((len = bis.read(data))!=-1){
                 // 写
                 bos.write(data,0,len);
             }
             bos.flush();
             System.out.println("成功");

         }catch(Exception e){
            System.out.println("失败");
            e.printStackTrace();
        }
    }
}
